/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbravo.pos.panels.model;

import cn.ekuma.data.ui.swing.AbstractDTOTableModel;
import cn.ekuma.epos.db.table.I_Product;

import com.openbravo.pos.base.AppConfig;

import com.openbravo.bean.Product;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;

/**
 *
 * @author Administrator
 */
public class ProductTableModel extends AbstractDTOTableModel<Product> {
    boolean showBuyPrice;
    

    public ProductTableModel() {
		super();
		showBuyPrice="true".equals(AppConfig.getAppProperty(AppConfig.SHOW_BUY_PRICE));
	}


	@Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Product inculdProduct = objs.get(rowIndex);
         switch(columnIndex){
             case 0:
                  return inculdProduct.getReference();
             case 1:
                 return inculdProduct.getCode();
             case 2:
                 return inculdProduct.getName();
             case 3:
                 return inculdProduct.getSpecification();           
             case 4:
                 return showBuyPrice==true?inculdProduct.getPriceBuy():"***";
             case 5:
                 return inculdProduct.getPriceSell();
             case 6:    
             	return inculdProduct.getM_dCustomerPrice();
             case 7:    
              	return inculdProduct.getM_dWholesalePrice();
             case 8:
            	 return inculdProduct.getM_sManufacturer();
             case 9:
            	 return inculdProduct.getM_origin();
             case 10:
            	 return inculdProduct.getM_iDurability();
             case 11:
            	 return inculdProduct.isCom()?"Y":" ";
             case 12:
            	 return inculdProduct.getM_quantity();
             case 13:
            	 return showBuyPrice==true?Formats.PERCENT.formatValue(new Double(inculdProduct.getPriceSell() / inculdProduct.getPriceBuy() - 1.0)):"***";
             case 14:
            	 return showBuyPrice==true?inculdProduct.getM_quantity()>1?Formats.CURRENCY.formatValue(inculdProduct.getPriceBuy()* inculdProduct.getM_quantity()):" ":"***";
             case 15:
            	 return inculdProduct.getM_quantity()>1?Formats.CURRENCY.formatValue(inculdProduct.getPriceSell()* inculdProduct.getM_quantity()):" ";
         }
         return null;
    }


    public String[] getColumnNames() {
        return new String[] {
        		AppLocal.getIntString("label.prodref"),
        		AppLocal.getIntString("label.prodbarcode"),
                AppLocal.getIntString("label.prodname"),
                AppLocal.getIntString("label.prodSpecification"),
                AppLocal.getIntString("label.prodpricebuy"),
                AppLocal.getIntString("label.prodpricesell"),
                AppLocal.getIntString("label.baseCustomerPrice"),
                AppLocal.getIntString("label.WholesalePrice"),
                AppLocal.getIntString("label.prodcut.m_sManufacturer"),
                AppLocal.getIntString("label.product.origin"),
                AppLocal.getIntString("label.product.m_iDurability"),
                AppLocal.getIntString("label.prodaux"),
                AppLocal.getIntString("label.product.quantity"),
                AppLocal.getIntString("label.profits"),
                AppLocal.getIntString("label.pricebuyCount"),
                AppLocal.getIntString("label.pricesellCount")
                };
    }


	public void setObject(int row, Product obj) {
		objs.set(row, obj);
	}
	
	public static Field[] getQBFFields(){
		return getQBFFields(null);
	}
	
	public static Field[] getQBFFields(String pref){
		return new Field[]{
				new Field(pref!=null?pref+"."+I_Product.REFERENCE:I_Product.REFERENCE, Datas.STRING, Formats.STRING,AppLocal.getIntString("label.prodref")),
				new Field(pref!=null?pref+"."+I_Product.CODE:I_Product.CODE, Datas.STRING, Formats.STRING,AppLocal.getIntString("label.prodbarcode")),
				new Field(pref!=null?pref+"."+I_Product.NAME:I_Product.NAME, Datas.STRING, Formats.STRING,AppLocal.getIntString("label.prodname")),		
				new Field(pref!=null?pref+"."+I_Product.PRICEBUY:I_Product.PRICEBUY, Datas.DOUBLE, Formats.CURRENCY,AppLocal.getIntString("label.prodpricebuy")),
				new Field(pref!=null?pref+"."+I_Product.PRICESELL:I_Product.PRICESELL, Datas.DOUBLE, Formats.CURRENCY,AppLocal.getIntString("label.prodpricesell")),
				new Field(pref!=null?pref+"."+I_Product.CUSTOMERPRICESELL:I_Product.CUSTOMERPRICESELL, Datas.DOUBLE,Formats.CURRENCY,AppLocal.getIntString("label.baseCustomerPrice")),
				new Field(pref!=null?pref+"."+I_Product.WHOLESALEPRICE:I_Product.WHOLESALEPRICE, Datas.DOUBLE,Formats.CURRENCY,AppLocal.getIntString("label.WholesalePrice")),
				new Field(pref!=null?pref+"."+I_Product.ORIGIN:I_Product.ORIGIN, Datas.STRING, Formats.STRING,AppLocal.getIntString("label.product.origin")),
				new Field(pref!=null?pref+"."+I_Product.QUANTITY:I_Product.QUANTITY, Datas.DOUBLE, Formats.DOUBLE,AppLocal.getIntString("label.product.quantity")),
				new Field(pref!=null?pref+"."+I_Product.MANUFACTUR:I_Product.MANUFACTUR, Datas.STRING, Formats.STRING,AppLocal.getIntString("label.prodcut.m_sManufacturer")),
				//new Field(I_Product.SIMILARCODE, Datas.STRING, Formats.STRING),
				//new Field(I_Product.DURABILITY, Datas.INT, Formats.INT),
				//new Field(I_Product.MNEMONIC, Datas.STRING, Formats.STRING),
				new Field(pref!=null?pref+"."+I_Product.MANUFACTURING:I_Product.MANUFACTURING, Datas.BOOLEAN, Formats.BOOLEAN, AppLocal.getIntString("label.product.m_iDurability"))
				//new Field(I_Product.WHOLESALEPRICE, Datas.DOUBLE,Formats.CURRENCY),
				//new Field(I_Product.CURDATE, Datas.TIMESTAMP,Formats.TIMESTAMP)
		};
	}
}

